import 'dart:isolate';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:image/image.dart';
import 'package:image_picker/image_picker.dart';

Future<Uint8List> pickImage() async {
  var picker = ImagePicker();
  var file =
      await picker.pickImage(source: ImageSource.gallery, imageQuality: 0);
  return file!.readAsBytes();
}

/*class CompressParam {
  Image image;
  int h;
  int w;
  SendPort sendPort;

  CompressParam(this.image, this.h, this.w, this.sendPort);
}

/*Future<Uint8List> compressListIsolate(Uint8List uint8list) async {
  var image = decodeImage(uint8list)!;
  // Resize the image to a 120x? thumbnail (maintaining the aspect ratio).
  var receivePort = ReceivePort();

  await Isolate.spawn(
      (p) {
        var compressed = copyResize(p.image, height: p.h, width: p.w);
        p.sendPort.send(compressed);
      }, CompressParam(image, 120, 120, receivePort.sendPort));

  // Get the processed image from the isolate.
  var compressed = await receivePort.first as Image;

  return Uint8List.fromList(encodeJpg(compressed));
}*/
Future<Uint8List> compressListIsolate(Uint8List uint8list) async {
  return compute(compressList, uint8list);
}

Uint8List compressList(Uint8List uint8list) {
  var image = decodeImage(uint8list)!;
  var compressed =
      copyCrop(image, image.width ~/ 2, image.height ~/ 2, 120, 120);

  return Uint8List.fromList(encodePng(compressed));
}*/

class MyClipper extends CustomClipper<Rect> {
  final double a;

  MyClipper(this.a);

  @override
  Rect getClip(Size size) =>
      Rect.fromLTWH(size.width / 2 - a / 2, size.height / 2 - a / 2, a, a);

  @override
  bool shouldReclip(CustomClipper<Rect> oldClipper) => false;
}

